package jisuanji;

import java.awt.geom.Path2D;
import java.awt.Shape;

public class Triangle extends MyShape {
    private double a, b, c;
    
    public Triangle(double a, double b, double c) {
        super("三角形");
        this.a = a;
        this.b = b;
        this.c = c;
    }
    
    @Override
    public double getPerimeter() {
        return a + b + c;
    }
    
    @Override
    public double getArea() {
        double s = getPerimeter() / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
    }
    
    @Override
    public Shape getRealShape() {
        double cosA = (b * b + c * c - a * a) / (2 * b * c);
        double h = 2 * getArea() / c;
        Path2D path = new Path2D.Double();
        path.moveTo(0, 0);
        path.lineTo(c, 0);
        path.lineTo(b * cosA, h);
        path.closePath();
        return path;
    }
}